<?php

namespace app\admin\model;


/**
 * 私人定制模型
 * Class InformationClassification
 * @package app\admin\model
 */
class Customized extends Base
{
    protected $autoWriteTimestamp = true;//开启自动添加时间戳
    protected $updateTime = false;

    //私人定制列表
    public function customizedList($keyword = ""){
        return $this
            ->where(function ($q)use ($keyword){
                if(!empty($keyword)){
                    $q->whereOr("tel","like","%".$keyword."%");
                }
            })
            ->where(function ($q){
                if(!empty($this->substations)){//是否设置了当前网站
                    $q->where("substation_id",$this->substations);
                }else{
                    if($this->admin["group_id"] != config("SuperAdminGroupId")) {//是否超级管理员
                        $arr = [];
                        $Substation = new Substation();//分站类
                        $userList = $Substation->userList();//获取分站集合
                        foreach ($userList as $val){
                            $arr[] = $val['substation_id'];
                        }
                        $q->where("substation_id","in",$arr);
                    }
                }
            })
            ->order("create_time DESC")
            ->page($this->after_page)
            ->limit($this->after_limit)
            ->select();
    }

    //私人定制列表总数
    public function customizedListCount($keyword = ""){
        return $this
            ->where(function ($q)use ($keyword){
                if(!empty($keyword)){
                    $q->whereOr("tel","like","%".$keyword."%");
                }
            })
            ->where(function ($q){
                if(!empty($this->substations)){//是否设置了当前网站
                    $q->where("substation_id",$this->substations);
                }else{
                    if($this->admin["group_id"] != config("SuperAdminGroupId")) {//是否超级管理员
                        $arr = [];
                        $Substation = new Substation();//分站类
                        $userList = $Substation->userList();//获取分站集合
                        foreach ($userList as $val){
                            $arr[] = $val['substation_id'];
                        }
                        $q->where("substation_id","in",$arr);
                    }
                }
            })
            ->count();
    }
}